/**
 * @description: 管理员权限相关接口
 * @version: 0.0.1
 * @author: z..
 * @Date: 2023-06-12 18:16:39
 */

import { Inject, Controller, Post, Body, Get, Query } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { UserService } from '../service/user.service';
import { UpdateUserDTO, DeptIdDTO, UpdateUserAmountDTO, ChangeRoleDTO } from '../dto/user';
import { PageDTO } from "../dto/common";
import {
  AdminWorkingPageDTO, DownloadAdminWorkingFileDTO,
  UpdateJsonConfigDataDTO, InsertJsonConfigDataDTO,
  ChartsDataDTO
} from "../dto/admin"
import { UnionIdDTO } from "../dto/common"
import { WorkingService } from "../service/working.service";
import { WorkingDepartService } from "../service/working.depart.service";
import { AppConfigService } from "../service/app.config.service";
import { NotFormat } from "../decorator/not.format"


@Controller('/api/v1/admin')
export class Admin {
  @Inject()
  ctx: Context;

  @Inject()
  UserService: UserService;

  @Inject()
  WorkingService: WorkingService;

  @Inject()
  WorkingDepartService: WorkingDepartService;

  @Inject()
  AppConfigService: AppConfigService;

  /**
   * @summary 管理员 用户关联
   * @description 管理员 用户关联
   * @router post /api/v1/admin/user/getUserList
   * @request body deptId  *body
   * @response 200 baseResponse 返回结果
   */
  @Post('/user/getUserList')
  async getUserList(@Body() options: PageDTO): Promise<any> {
    return await this.UserService.getUserList(options);
  }

  /**
   * @summary 管理员 修改用户权限信息
   * @description 管理员 修改用户权限信息
   * @router post /api/v1/admin/user/updateUserById
   * @request body deptId  *body
   * @response 200 baseResponse 返回结果
   */
  @Post('/user/updateUserById')
  async updateUserById(@Body() options: UpdateUserDTO): Promise<any> {
    return await this.UserService.updateUserById(options);
  }

  /**
   * @summary 管理员 修改用户工时金额
   * @description 管理员 修改用户工时金额
   * @router post /api/v1/admin/user/updateUserHoursAmount
   * @request body deptId  *body
   * @response 200 baseResponse 返回结果
   */
  @Post('/user/updateUserHoursAmount')
  async updateUserHoursAmount(@Body() options: UpdateUserAmountDTO): Promise<any> {
    return await this.UserService.updateUserHoursAmount(options);
  }


  /**
    * 工时汇总
    */
  /**
   * @summary 项目列表分页查询
   * @description 项目列表分页查询
   * @router post /api/v1/admin/working/getWorkingPage
   * @request body pageNum  *body
   * @request body pageSize  *body
   * @request body searchKey  *body
   * @request body deptId  *body
   * @response 200 baseResponse 返回结果
   */
  @Post('/working/getWorkingPage')
  async getAdminWorkingPage(@Body() options: AdminWorkingPageDTO): Promise<any> {
    return await this.WorkingService.getAdminWorkingPage(options);
  }

  /**
   * @summary 项目列表分页查询
   * @description 项目列表分页查询
   * @router get /api/v1/admin/working/getWorkingPage
   * @request body pageNum  *body
   * @request body pageSize  *body
   * @request body searchKey  *body
   * @response 200 baseResponse 返回结果
   */
  @NotFormat()
  @Get('/working/downloadAdminWorkingFile')
  async downloadAdminWorkingFile(@Query() options: DownloadAdminWorkingFileDTO): Promise<any> {
    return await this.WorkingService.downloadAdminWorkingFile(options);
  }

  /**
   * 部门工时汇总查询
   */
  @Post('/working/getAllWorkingPageByDeptId')
  async getAllWorkingPageByDeptId(@Body() options: DeptIdDTO): Promise<any> {
    return await this.WorkingDepartService.getAllWorkingPageByDeptId(options);
  }

  /**
   * 获取用户所有工时数据
   */
  @Post('/working/getWorkingDataByUserId')
  async getWorkingDataByUserId(@Body() options: UnionIdDTO): Promise<any> {
    return await this.WorkingDepartService.getWorkingDataByUserId(options);
  }

  /**
  * @summary 工时汇总图表数据获取
  * @description 工时汇总图表数据获取
  * @router get /api/v1/admin/working/getChartsData
  * @response 200 baseResponse 返回结果
  */
  @Post('/working/getChartsData')
  async getChartsData(@Body() options: ChartsDataDTO): Promise<any> {
    return await this.WorkingDepartService.getChartsData(options);
  }

  /**
    * @summary 分页查询配置数据
    * @description 分页查询配置数据
    * @router post /api/v1/admin/appconfig/getJsonConfigList
    * @response 200 baseResponse 返回结果
    */
  @Post('/jsonconfig/getJsonConfigList')
  async getJsonConfigList(@Body() options: PageDTO): Promise<any> {
    return await this.AppConfigService.getJsonConfigList(options);
  }

  /**
  * @summary 新增配置数据
  * @description 新增配置数据
  * @router post /api/v1/admin/jsonconfig/insertJsonConfigData
  * @response 200 baseResponse 返回结果
  */
  @Post('/jsonconfig/insertJsonConfigData')
  async insertJsonConfigData(@Body() options: InsertJsonConfigDataDTO): Promise<any> {
    return await this.AppConfigService.insertJsonConfigData(options);
  }

  /**
  * @summary 修改配置数据
  * @description 修改配置数据
  * @router post /api/v1/admin/jsonconfig/updateJsonConfigData
  * @response 200 baseResponse 返回结果
  */
  @Post('/jsonconfig/updateJsonConfigData')
  async updateJsonConfigData(@Body() options: UpdateJsonConfigDataDTO): Promise<any> {
    return await this.AppConfigService.updateJsonConfigData(options);
  }


  /**
  * @summary 获取部门树
  * @description 获取部门树
  * @router get /api/v1/admin/jsonconfig/getDeptTree
  * @response 200 baseResponse 返回结果
  */
  @Get('/jsonconfig/getDeptTree')
  async getDeptTree(): Promise<any> {
    return await this.AppConfigService.getDeptTree();
  }

  /**
   * @summary 管理员 修改用户角色信息
   * @description 管理员 修改用户角色信息
   * @router post /api/v1/admin/user/changeRole
   * @request body userId  *body
   * @request body roleId  *body
   * @response 200 baseResponse 返回结果
   */
  @Post('/user/changeRole')
  async changeUserRole(@Body() options: ChangeRoleDTO): Promise<any> {
    return await this.UserService.updateUserRoleRecords(options);
  }
}
